<template>
  <div class="users_Box">
    <div class="Avatar_Backround_Box" :style="NoBouckroubdImg">
      <div class="Avatar_Backround">
        <div class="Like">
          <img src="../assets/icon/Like.png" alt="获赞数" />
          <div class="LikeTitle">{{this.$store.state.Like}}</div>
        </div>
        <div class="Avatar">
          <img :src="img||defaultImg" alt />
        </div>
        <div class="Edit" @click="Edit">
          <img class="EditImg" src="../assets/icon/edit.png" alt />
        </div>
      </div>
      <div class="Signature">{{Signature||DefaultPersonalSignature}}</div>
    </div>
    <div class="Notice">
      <img src="../assets/icon/Notice.png" alt />
      <div class="NoticeTitle">通知</div>
      <icon class="NoticeIcon" name="arrow" size="2em" color="#1296db" />
    </div>
    <div class="Notice">
      <img src="../assets/icon/wallet.png" alt />
      <div class="NoticeTitle">钱包</div>
      <icon class="NoticeIcon" name="arrow" size="2em" color="#1296db" />
    </div>
    <div class="Notice">
      <img src="../assets/icon/blacklist.png" alt />
      <div class="NoticeTitle">黑名单</div>
      <icon class="NoticeIcon" name="arrow" size="2em" color="#1296db" />
    </div>
    <div class="Notice">
      <img src="../assets/icon/coupon.png" alt />
      <div class="NoticeTitle">优惠劵</div>
      <icon class="NoticeIcon" name="arrow" size="2em" color="#1296db" />
    </div>

    <div class="Notice">
      <img src="../assets/icon/Notice.png" alt />
      <div class="NoticeTitle">分享flexapp趣事</div>
      <icon class="NoticeIcon" name="arrow" size="2em" color="#1296db" />
    </div>

    <Button @click="dropout()" class="drop_out" :type="ButtonType">{{loginText}}</Button>
  </div>
</template>
<script>
import { Icon, Button } from "vant";
export default {
  data() {
    return {
      loginText:"立即登陆",
      ButtonType:"primary",//danger
      publicPath: process.env.BASE_URL,
      img: "",
      defaultImg: require("../assets/images/activityImages/grayHead.png"),
      key: 1,
      Signature: "",
      DefaultPersonalSignature: "个性签名",
      NoUrl: require("../assets/images/activityImages/u=1090996759,4033579234&fm=26&gp=0.jpg"),

      NoBouckroubdImg: ""
    };
  },
  components: {
    Icon,
    Button
  },

  beforeCreate: function() {
    // 在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
  },
  created: function() {
    console.log(this.publicPath);
    // 在实例创建完成后被立即调用。在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。然而，挂载阶段还没开始，el 属性目前尚不可用。

    this.click(this.key);
  },
  beforeMount: function() {},
  methods: {
    // 在挂载开始之前被调用：相关的 render 函数首次被调用。

    click(Vlue, key) {
      this.$store.state.Title = "我的";
      this.$store.state.arrow = false;
      this.$store.state.LeftTitle = "";
      let user = JSON.parse(localStorage.getItem("user"));
      if (user) {
        this.NoBouckroubdImg =
          "background-image: url('" + user.BugroundImg + "');";
        this.img = user.AvatarImg;
        this.$store.state.Like = user.Like;
        this.Signature = user.Signature;
        this.loginText = "退出登录";
        this.ButtonType = "danger"
      }
      // 判断登录后改变默认头像和个性签名
      let login = JSON.parse(localStorage.getItem("login"));
      if (login === false) {
        this.$store.state.Like = 0;
        this.img = "";
         this.NoBouckroubdImg = "background-image: url('" + this.NoUrl + "');";
          this.loginText = "立即登录";
      this.ButtonType = "primary";
      const login = "/login/"
       
      }
    },
    // 编辑
    Edit() {
      this.ToastFunction("/Edit/", 1);
    },
    dropout() {
      //  退出登录
      localStorage.setItem("login", JSON.stringify(false));
      this.$store.state.Like = 0;
      localStorage.removeItem("user");
      this.img = "";
      this.Signature = "";
      this.$store.state.login=false;
      this.$store.state.cart = 0;
      this.NoBouckroubdImg = "background-image: url('" + this.NoUrl + "');";
      this.loginText = "立即登录";
      this.ButtonType = "primary";
      const login = "/login/"
      this.ToastFunction(login)
      this.Toast("已经退出登录");
    }
  }
};
</script>

<style lang="scss" scope>
.users_Box {
  width: 100%;
  height: 20rem;
  display: flex;
  flex-direction: column;
  

  .Avatar_Backround_Box {
    width: 100%;
    height: 5rem;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    background-color: rgba(0, 0, 0, 0.7);

    background-repeat: no-repeat;
    background-position: center;
    order: 1;
    .Avatar_Backround {
      width: 100%;
      height: 2.6rem;
      display: flex;
      flex-wrap: nowrap;
      justify-content: space-between;
      align-items: center;
      .Like {
        height: 1rem;
        width: 2rem;
        align-self: flex-start;
        margin-top: 0.3rem;
        margin-left: 0.2rem;
        display: flex;
        justify-items: center;
        align-items: center;
        img {
          width: 0.6rem;
          height: 0.6rem;
        }
        .LikeTitle {
          font-size: 0.3rem;
          color: #ffffff;
          color: #d81e06;
          font-size: 0.45rem;
          font-weight: 100;
          font-family: "Courier New", Courier, monospace;
          margin-left: 0.2rem;
        }
      }
      .Avatar {
        width: 1.6rem;
        height: 1.6rem;
        border-radius: 50%;
        overflow: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 1rem;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .Edit {
        height: 1rem;
        width: 1rem;
        align-self: flex-start;
        // border: 1px solid red;
        margin: 0.3rem 0.2rem 0 0;
        display: flex;
        justify-content: center;
        align-items: center;
        .EditImg {
          width: 0.6rem;
          height: 0.6rem;
        }
      }
    }

    .Signature {
      width: 100%;
      height: 0.7rem;
      line-height: 0.7rem;
      text-align: center;
      color: #f4ea2a;
    }
  }

  //  通知
  .Notice {
    height: 1.5rem;
    width: 100%;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: space-between;
    background-color: rgba(0, 0, 0, 0.7);
    order: 2;
    margin: 0.05rem 0;
    img {
      width: 0.5rem;
      height: 0.5rem;
      margin-left: 0.3rem;
    }
    .NoticeTitle {
      padding: 0 0.3rem;
      font-size: 0.45rem;
      color: white;
      font-weight: 100;
      font-family: "Courier New", Courier, monospace;
    }
    .van-icon-arrowceIcon {
      margin-right: 0.3rem;
    }
  }
  .drop_out {
    width: 100%;
    order: 10;
    height: 1rem;
  }
}
 
</style>